var model = new Model();

function Model() {
    this.options = new Object();
    this.votes = new Object();
    this.getVoteFor = _method_getVoteFor;
}

function Option(id, caption) {
    this.id = id;
    this.caption = caption;
    this.voters = new Array();
    this.containsAnyVoteFrom = _method_containsAnyVoteFrom;
}

function Vote(optionId, participantId, answer) {
    this.optionId = optionId;
    this.participantId = participantId;
    this.answer = answer;
}

function _method_containsAnyVoteFrom(participantId) {
    var participantId_escaped = encodeURIComponent(participantId);
    for ( var idx in this.voters) {
		var voter = this.voters[idx];
		var hasVoted = (voter == participantId_escaped);
		if (hasVoted) {
		    return true;
		}
    }
    return false;
}

/**
 * Return the vote or null, if no vote is present.
 * 
 * @param optionId
 * @param participantId
 */
function _method_getVoteFor(optionId, participantId){
    for (var key in model.votes){
		var vote = model.votes[key];
		if (vote.optionId == optionId && vote.participantId == participantId){
		    return vote.answer;
		}
    }
    return null;
}
